from django.contrib import admin
from students.models import StudentProfile
from students.forms import *


# Register your models here.

class StudentProfileAdmin(admin.ModelAdmin):
    list_display = ['uid', 'username', 'gender', 'phone', 'email']
    list_display_links = ['uid', 'username', 'gender', 'phone', 'email']
    search_fields = ('uid', 'username', 'phone', 'email')

    def get_form(self, request, obj, **kwargs):
        """
        根据用户返回表单
        :param request:
        :param obj:
        :param kwargs:
        :return:
        """
        # print("obj.author1", obj.author)
        # print("request1", request.user)
        if obj is None:
            kwargs['form'] = UserCreationForm
        else:
            kwargs['form'] = UserChangeForm
        return super(StudentProfileAdmin, self).get_form(request, obj, **kwargs)


admin.site.register(StudentProfile, StudentProfileAdmin)
